home *** CD-ROM | disk | FTP | other *** search
- /*
- cvsketch.cpp
-
- Sketch pad example
-
- C++/Views 2.0 Demo
- Copyright (c) 1992, by Liant Software Corp.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- */
-
- #include "cvsketch.h"
- #include "cvdemovw.h"
- #include "notifier.h"
- #include "port.h"
- #include "pen.h"
- #include "cvcolor.h"
- #include "pointrry.h"
-
- defineClass(SketchView, VMdiView)
-
- SketchView::SketchView()
- {
- ;
- }
-
- SketchView::SketchView(VFrame &f, DemoAppView *parent)
- : VMdiView("SketchIcon", f, (VWindow *) parent, StyleBorder | StyleTitle | StyleCloseBox | StyleSizable)
- {
- mainWin = parent;
-
- setTitle("C++/Views Sketch Pad Example");
-
- /* create a port for graphics output */
- aPort = new VPort(this);
- aPen = new VPen(BLACK);
-
- aPort->usePen(aPen);
-
- /* create a color select control */
- colorBox = new ColorControl(VFrame(0, 0, 120, 50), this, StyleBorder);
- colorBox->uponClick(this, methodOf(SketchView, newColor));
-
- /* create a point array */
- points = new VPointArray(22);
-
- /* make sure the "About this Window" data is set up */
- mainWin->setAboutNames("Sketch:About", "cvsketch.cpp");
- }
-
- SketchView::~SketchView()
- {
- if (aPort) {
- aPort->free();
- }
-
- if (aPen) {
- aPen->free();
- }
-
- delete points;
- }
-
- boolean SketchView::free()
- {
- delete this;
- return(TRUE);
- }
-
- boolean SketchView::paint()
- /*
- Called by the window manager,
- repaint the contents of our window
- */
- {
- aPort->open();
- aPort->drawLines(points);
- aPort->close();
- return(TRUE);
- }
-
- boolean SketchView::close()
- /*
- The user has closed the window.
- Notify the main window so that it can update the main menu bar
- */
- {
- mainWin->sketchView = 0;
- mainWin->updateMenu();
- return(FALSE);
- }
-
- boolean SketchView::mouseDn(int mx, int my)
- /*
- Called when a mouse button has been pressed down
- within this window with the coordinates of the mouse.
- */
- {
- notifier->captureMouseFor(this);
- notifier->mouseTracking(TRUE);
-
- points->reset();
- update();
-
- aPort->open();
- aPort->moveTo(mx, my);
- points->add(mx, my);
-
- return(TRUE);
- }
-
- boolean SketchView::mouseMv(int mx, int my, int bStat)
- /*
- Called if mouse tracking enabled, indicating the current
- position and mouse button status.
- If 'bStat' is TRUE then the mouse button is down, else FALSE.
- */
- {
- if (bStat) {
- /* draw connecting line, add the point to the array */
- aPort->lineTo(mx, my);
- points->add(mx, my);
- return(TRUE);
- }
- else {
- return(FALSE);
- }
- }
-
- boolean SketchView::mouseUp(int mx, int my)
- /*
- Called when a mouse button has been released
- within this window with the coordinates of the mouse.
- */
- {
- notifier->releaseCapture();
- notifier->mouseTracking(FALSE);
-
- aPort->close();
- update();
-
- return(TRUE);
- }
-
- boolean SketchView::newColor()
- /*
- New color selected in the color select control
- */
- {
- if (aPen) {
- aPen->color(colorBox->getColor());
- update();
- }
-
- return(TRUE);
- }
-
- boolean SketchView::givenFocus()
- /*
- Our window has just been given input focus
- */
- {
- /* set the data for the About this Window dialog */
- mainWin->setAboutNames("Sketch:About", "cvsketch.cpp");
-
- /* carry on with default window behavior, return FALSE */
- return(FALSE);
- }
-
-